package NO06;

import java.util.Stack;

/**
 * 用两个栈来模拟队列
 * @author swg
 *
 */
public class StackToQueue {
	private static Stack<Integer> stack1 = new Stack();
	private static Stack<Integer> stack2 = new Stack();
	
	public static void push(int node){
		stack1.push(node);
	}
	
	/*
	 * 取数据只从stack2中取，存数据只到stack1中存，如果stack2空了，就立即将stack1中的元素全放进去
	 */
	public static int pop(){
		if(stack2.isEmpty()){
			while(!stack1.isEmpty()){
				stack2.push(stack1.pop());
			}
		}
		
		return stack2.pop();
	}
	
	public static void main(String[] args) {
		push(1);
		push(2);
		push(3);
		
		System.out.println(pop());
		System.out.println(pop());
		System.out.println(pop());
	}
	
}
